/*******
 * @author 大兵
 * @desc QQ:63399633
 * @desc QQ群:697732720
 * git地址 https://gitee.com/lybuser/spring-cloud-all.git
 * 代码配套视频教程  http://m.study.163.com/provider/480000001914549/index.htm?share=2&shareId=480000001914549
 */
package com.fire.cloud.consumer.controller;

import com.fire.cloud.consumer.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.loadbalancer.LoadBalancerClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RestController
public class MovieController {
  @Autowired
  private RestTemplate restTemplate;

  @Autowired
  private LoadBalancerClient loadBalancerClient;

//  @GetMapping("/movie/{id}")
//  public User findById(@PathVariable Long id) {
//    return this.restTemplate.getForObject(this.userServicePath + id, User.class);
//  }

    @GetMapping("/movie/{id}")
    public User findById(@PathVariable Long id) {
        return this.restTemplate.getForObject("http://provider-user/simple/" + id, User.class);
    }


  @GetMapping("/test")
  public String test() {
    ServiceInstance serviceInstance = this.loadBalancerClient.choose("provider-user");
    System.out.println("111" + ":" + serviceInstance.getServiceId() + ":" + serviceInstance.getHost() + ":" + serviceInstance.getPort());
    return "1";
  }

}
